package com.yonyougov.devops.cruxcisupport.commitdevelopuser;

import com.yonyougov.devops.cruxcisupport.commitdevelopuser.vo.ContextDevelopUserVo;
import com.yonyougov.devops.cruxcisupport.util.CruxDevOpsIdGenerator;
import com.yonyougov.devops.fwc.core.dao.BaseDao;
import com.yonyougov.devops.fwc.core.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.LinkedList;
import java.util.List;

/**
 * t_commit_develop_user服务实现
 */
@Service
public class CommitDevelopUserServiceImpl extends BaseServiceImpl<CommitDevelopUserEntity, BigInteger> implements CommitDevelopUserService {
    @Autowired
    private CommitDevelopUserDao commitDevelopUserDao;

    @Override
    public BaseDao<CommitDevelopUserEntity, BigInteger> getDao() {
        return commitDevelopUserDao;
    }
    //<!--用户自定义代码开始-->

    @Override
    public void batchInsert(List<ContextDevelopUserVo> developUserVos) {
        List<CommitDevelopUserEntity> userEntityList = new LinkedList<>();
        developUserVos.forEach(d -> d.getDevelopUserId().forEach(u -> {
            CommitDevelopUserEntity developUserEntity = new CommitDevelopUserEntity();
            developUserEntity.setId(new CruxDevOpsIdGenerator().generatorId(commitDevelopUserDao));
            developUserEntity.setDevelopUserId(u);
            developUserEntity.setCommitContextId(d.getCommitContextId());
            userEntityList.add(developUserEntity);
        }));
        commitDevelopUserDao.batchInsert(userEntityList);
    }


    //<!--用户自定义代码结束-->
}
